<template>
  <div class="choose-lib">
    <div class="table-data">
      <el-collapse-transition>
        <section class="main-search merge">
          <span class="svg-container">
            <svg-icon icon-class="search" />
          </span>
          <el-input v-model.trim="listQuery.name" placeholder="输入视频名称搜索" class="search-input" @keyup.enter.native="handleFilter" />
          <section class="search-btn">
            <el-button class="filter-item" type="primary" @click="handleFilter">搜索</el-button>
            <el-button type="primary" @click="handleReset">重置</el-button>
          </section>
        </section>
      </el-collapse-transition>
      <v-table
        :list="tableData"
        :height="440"
        :selection="false"
        :filter-column="filtercolumn"
        tag="contentVideoLibrar"
        :source-arr="['subjectImgUrl']"
      >
        <el-table-column
          fixed="right"
          label="操作"
          width="120"
          align="center"
        >
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="handleSelect(scope.row)">选择</el-button>
          </template>
        </el-table-column>
      </v-table>
    </div>
    <div class="page">
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.limit"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { queryFileList } from './api'
import Pagination from '@/components/Pagination'
import VTable from '@/components/Table'
export default {
  name: 'ChoosePic',
  components: { Pagination, VTable },
  data() {
    return {
      listLoading: false,
      total: 0,
      tableData: [],
      listQuery: {
        page: 1,
        limit: 10,
        name: ''
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleSelect(info) {
      this.$emit('select', info)
    },
    handleReset() {
      this.listQuery.page = 1
      this.listQuery.name = ''
      this.getList()
    },

    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    getList(obj) {
      this.listLoading = true
      var query = {
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.limit,
        subjectName: this.listQuery.name,
        subjectType: 'KCLX01',
        type: '2'
      }
      return new Promise((resolve, reject) => {
        queryFileList(query)
          .then((response) => {
            this.tableData = response.data.data.rows
            this.total = response.data.data.total
            this.listLoading = false
          })
          .catch((error) => {
            reject(error)
            this.listLoading = false
          })
      })
    },
    handleRegionList(row) {
      const arr = []
      if (row.areaProvinceName) {
        arr.push(row.areaProvinceName)
      }
      if (row.areaCityName) {
        arr.push(row.areaCityName)
      }
      if (row.areaCountyName) {
        arr.push(row.areaCountyName)
      }
      return arr.join('/')
    },
    filtercolumn(scope, item) {
      return scope.row[item] ? scope.row[item] : ''
    }
  }
}
</script>

<style type="text/css" lang="scss">
.choose-lib{
  height: 550px;
  display: flex;
  flex-direction: column;
  .main-search {
    background-color: #fff;
    padding: 0 10px;
    .svg-container {
      padding: 0 5px 0 10px;
      color: #bfced6;
      vertical-align: middle;
      display: inline-block;
    }
    .search-input {
      width: 60%;
      position: relative;
      &:after {
        content: '';
        position: absolute;
        left: -25px;
        right: 0;
        bottom: 8px;
        height: 1px;
        background: rgba(226, 227, 232, 1);
      }
      input {
        outline: none;
        background: transparent;
        border: none;
        outline: medium;
        padding: 0;
        &:focus {
          outline: none;
          background-color: transparent;
        }
      }
    }
    .search-btn {
      display: inline-block;
      float: right;
      .el-button.is-round {
        padding: 10px 30px;
        margin-right: 34px;
      }
      .search-more {
        font-size: 14px;
        font-weight: 500;
        @include font-color($mainColor);
        cursor: pointer;
        margin-left: 10px;
      }
    }

    &.merge {
      height: 50px;
      line-height: 50px;
    }
  }
  .table-data{
    flex: 1;
  }
  .page{
    height: 50px;
  }
}
</style>
